package com.it.myh;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 新增方式二：使用线程池
 */
class NumberThread implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i <= 100; i++) {
            if ( i % 2 != 0){
                System.out.println(i);
            }
        }
    }
}
public class Ev_0216_07 {

    public static void main(String[] args) {
        //1.提供指定线程数量的线程池：`Executors.newFixedThreadPool(n)`;
        // 创建一个可重用固定线程数的线程池。
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        //2.执行指定的线程的操作。需要提供实现Runnable接口或callable接口实现类的对象
        executorService.submit(new NumberThread());
        //3.关闭连接池
        executorService.shutdown();
    }
}
